package it.unibo.convoycruisecontrol.boatsubsystem.test.unit;

import static org.junit.Assert.*;
import it.unibo.convoycruisecontrol.boatsubsystem.AbstractStatusBoat;
import it.unibo.convoycruisecontrol.boatsubsystem.BoatStatusEvent;
import it.unibo.convoycruisecontrol.boatsubsystem.SensingBoatStatus;
import it.unibo.convoycruisecontrol.boatsubsystem.test.mock.MockSensingBoatStatus;
import it.unibo.convoycruisecontrol.boatsubsystem.test.mock.MockStatusBoat;
import it.unibo.is.interfaces.IMessage;
import it.unibo.util.information.InformationConverter;
import it.unibo.util.information.PrologInformationConverter;

import org.junit.BeforeClass;
import org.junit.Test;

public class SensingBoatStatusTestCase 
{
	static InformationConverter infoConverter;
	static MockSensingBoatStatus sensingStatus;
	String messageExpected1 = "enabled([],status(true),sequenceNumber(0))";
	String messageExpected2 = "enabled([],status(false),sequenceNumber(0))";
	String messageExpected3 = "enabled([],status(true),sequenceNumber(1))";
	static MockStatusBoat mockStatusBoat1;
	static MockStatusBoat mockStatusBoat2;
	static MockStatusBoat mockStatusBoat3;

	@BeforeClass
	public static void beforeClass()
	{
		try
		{
			infoConverter = new PrologInformationConverter();
			sensingStatus = new MockSensingBoatStatus(infoConverter);
			mockStatusBoat1 = new MockStatusBoat(0);
			mockStatusBoat1.setBroken(false);
			mockStatusBoat1.setEnabled(true);
			mockStatusBoat2 = new MockStatusBoat(0);
			mockStatusBoat2.setBroken(true);
			mockStatusBoat2.setEnabled(true);
			mockStatusBoat3 = new MockStatusBoat(1);
			mockStatusBoat3.setBroken(false);
			mockStatusBoat3.setEnabled(true);
		}
		catch (Exception e) {
			e.printStackTrace();
			fail();
		}
	}

	@Test
	public void testOnStatusChanged() 
	{
		try
		{
			sensingStatus.onStatusChanged(new BoatStatusEvent(mockStatusBoat1));
			assertEquals(messageExpected1, sensingStatus.getMessageSent());

			sensingStatus.onStatusChanged(new BoatStatusEvent(mockStatusBoat2));
			assertEquals(messageExpected2, sensingStatus.getMessageSent());

			sensingStatus.onStatusChanged(new BoatStatusEvent(mockStatusBoat3));
			assertEquals(messageExpected3, sensingStatus.getMessageSent());
		}
		catch (Exception e) {
			e.printStackTrace();
			fail();
		}
	}

	@Test(expected=IllegalArgumentException.class)
	public void testCreation() throws Exception
	{
		new SensingBoatStatus(null);
	}

}
